package org.apache.flink.runtime.rest.handler.job.metrics;

import java.util.Map;

import javax.annotation.Nullable;

import org.apache.flink.api.common.time.Time;
import org.apache.flink.runtime.rest.handler.HandlerRequest;
import org.apache.flink.runtime.rest.legacy.metrics.MetricFetcher;
import org.apache.flink.runtime.rest.legacy.metrics.MetricStore;
import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
import org.apache.flink.runtime.rest.messages.ConsumerIDPathParameter;
import org.apache.flink.runtime.rest.messages.job.metrics.JobMetricsHeaders;
import org.apache.flink.runtime.rest.messages.job.metrics.JobMetricsMessageParameters;
import org.apache.flink.runtime.rpc.retriever.GatewayRetriever;
import org.apache.flink.runtime.webmonitor.RestfulGateway;

/**
 * Request handler that returns for a given job a list of all available metrics or the values for a
 * set of metrics.
 */
public class ConsumerMetricsHandler extends AbstractMetricsHandler<JobMetricsMessageParameters> {

    public ConsumerMetricsHandler(
            final GatewayRetriever<? extends RestfulGateway> leaderRetriever,
            final Time timeout,
            final Map<String, String> headers,
            final MetricFetcher metricFetcher) {
        super(leaderRetriever, timeout, headers, JobMetricsHeaders.getInstance(), metricFetcher);
    }

    @Nullable
    @Override
    protected MetricStore.ComponentMetricStore getComponentMetricStore(
            final HandlerRequest<EmptyRequestBody> request, final MetricStore metricStore) {
        return metricStore.getConsumerMetricStore(
                request.getPathParameter(ConsumerIDPathParameter.class).toString());
    }
}
